/**
 * Created by shidaiapp on 2017/10/16.
 */
export const webList = (self, tiyData) => {
  self.$Spin.show();
  self.$apiOther.getCountryList({})
    .then(function (data) {
      self.$Spin.hide();
      self.$ySpliceAll(tiyData.tData.countryList, tiyData.tParam.selectedCountryIds);
      if (data.success) {
        tiyData.tParam.length = [];
        let list = data.result;
        list.forEach(
          function (item) {
            if(item.state===0){
              tiyData.tParam.selectedCountryIds.push(item.id);
            }
            tiyData.tData.countryList.push(item);
          }
        );
        if (0 === tiyData.tData.countryList.length) {
          self.$Message.error("查询没有结果");
        }
      } else {
        self.$Message.error(data.errorMessage);
      }
    });
}

export const saveCountry = (self, tiyData) => {
  self.$Spin.show();
  self.$apiOther.saveSelectedCountry(
    {selectedCountryIds:tiyData.tParam.selectedCountryIds.join(",")}
  ).then(
    function(data){
      if(data.success){
        self.$Message.success("保存成功");
        self.isCountriesChanged = false;
      }else{
        self.$Message.error(data.errorMessage);
      }
      self.$Spin.hide();
    }

  );

}

export const init=(self,tiyData)=>{
  webList(self,tiyData);
}




